#include<bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
int idx[N];
int px[N],py[N];
int A[N];
bool cmp1(int x,int y){
    return px[x] < px[y];
}
bool cmp2(int x,int y){
    return py[x] < py[y];
}
const int LMT = 2e6+10;
int lmt = 1;
int ncur;
struct KDT{
    struct zone{
        int x1,x2,y1,y2;
    } zs[N];
    int sum[N];
    int ls[N];
    int rs[N];
    int build(int l,int r){
        if(r < l){
            return 0;
        }
        if(l == r){ 
            int now = idx[l];
            sum[now] = A[now];
            zs[now] = {px[now],px[now],py[now],py[now]};
            return now; 
        }
        long long sx = 0;
        long long sx1 = 0;
        long long sy = 0;
        long long sy1 = 0;
        zone nw = {LMT,-LMT,LMT,-LMT};
        for(int i = l;i<=r;i++){
            sx += px[idx[i]];
            sx1 += 1ll*px[idx[i]]*px[idx[i]];
            sy += py[idx[i]];
            sy1 += 1ll*py[idx[i]]*py[idx[i]];
            nw.x1 = min(nw.x1,px[idx[i]]);
            nw.x2 = max(nw.x2,px[idx[i]]);
            nw.y1 = min(nw.y1,py[idx[i]]);
            nw.y2 = max(nw.y2,py[idx[i]]);
        }
        int len = r - l + 1;
        int mid = (l + r)/2;
        int now;
        double va = 1.0*sx1/len - (1.0*sx/len)*(1.0*sx/len),vb = 1.0*sy1/len - (1.0*sy/len) * (1.0*sy/len);
        if(va > vb){
            nth_element(idx + l,idx + mid,idx + r + 1,cmp1);
            now = idx[mid];
        }else{
            nth_element(idx + l,idx + mid,idx + r + 1,cmp2);
            now = idx[mid];
        }
        zs[now] = nw;
        ls[now] = build(l,mid - 1);
        rs[now] = build(mid+1,r);
        sum[now] = A[now] + sum[ls[now]] + sum[rs[now]];
        return now;
    }
    bool included(zone outer,zone inner){
        return outer.x1 <= inner.x1 && inner.x2 <= outer.x2 && outer.y1 <= inner.y1 && inner.y2 <= outer.y2;
    }
    bool wu(zone a,zone b){
        return a.x2 < b.x1 || b.x2 < a.x1 || a.y2 < b.y1 || b.y2 < a.y1;
    }
    int query(int now,zone val){
        if(included(val,zs[now])){
            return sum[now];
        }
        int su = 0;;
        if(val.x1 <= px[now] && px[now] <= val.x2 && val.y1 <= py[now] && py[now] <= val.y2){
            su += A[now];
        }
        if(ls[now] && !wu(zs[ls[now]],val)){
            su += query(ls[now],val);
        }
        if(rs[now] && !wu(zs[rs[now]],val)){
            su += query(rs[now],val);
        }
        return su;
    }
    void clear(int now){
        if(!now){
            return;
        }
        if(ls[now]){
            clear(ls[now]);
        }
        if(rs[now]){
            clear(rs[now]);
        }
        ls[now] = rs[now] = 0;
    }
}kdt;
const int BLO = 1824;
int main(){
    int N;
    cin>>N;
    int op;
    cin>>op;
    int rot = 0;
    int lastans = 0;
    while(op != 3){
        if(op == 1){
            ncur++;
            idx[ncur] = ncur;
            int x,y,v;
            cin>>px[ncur]>>py[ncur]>>A[ncur];
            px[ncur]^=lastans;
            py[ncur]^=lastans;
            A[ncur]^=lastans;
            if(ncur - lmt + 1 > BLO){
                kdt.clear(rot);
                rot = kdt.build(1,ncur);
                lmt = ncur + 1;
            }
        }else if(op == 2){
            int x1,x2,y1,y2;
            cin>>x1>>y1>>x2>>y2;
            x1^=lastans;
            x2^=lastans;
            y1^=lastans;
            y2^=lastans;
            KDT::zone val = {x1,x2,y1,y2};
            lastans = 0;
            if(rot && !kdt.wu(kdt.zs[rot],val)){
                lastans += kdt.query(rot,val);
            }
            for(int i = lmt;i <= ncur;i++){
                if(x1 <= px[i] && px[i] <= x2 && y1 <= py[i] && py[i] <= y2){
                    lastans += A[i];
                }
            }
            cout<<lastans<<"\n";
        }
        cin>>op;
    }
}